package com.tma.android.gpm.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnFocusChangeListener;
import android.widget.ArrayAdapter;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
import com.actionbarsherlock.widget.SearchView;
import com.tma.android.gpm.R;
import com.tma.android.gpm.common.ConstantCommon;
import com.tma.android.gpm.fragment.GPMArtistsFragment;
import com.tma.android.gpm.fragment.GPMRecentFragment;

public class MainActivity extends SherlockFragmentActivity {

	private Context mContext;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		mContext =this;
		   /** */
        final ActionBar ab = getSupportActionBar();
        ab.setDisplayShowTitleEnabled(false);
        ab.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
//       ab.setBackgroundDrawable(getResources().getDrawable(R.drawable.ab_bg_black));
     
        ArrayAdapter<CharSequence> list = ArrayAdapter.createFromResource(this, R.array.MenuDropDownItem, R.layout.main_menu_item);
        list.setDropDownViewResource(R.layout.dropdown_main_menu_item);
        
        // set up list nav
        ab.setListNavigationCallbacks(list,
                new OnNavigationListener() {
                    public boolean onNavigationItemSelected(int itemPosition,
                            long itemId) {
                        // FIXME add proper implementation
				switch (itemPosition) {
				case ConstantCommon.RECENT_SCREEN_ID:
					// Add the fragment to the activity, pushing this transaction
			        // on to the back stack.
					FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
			        ft.replace(R.id.fragment_item, new GPMRecentFragment());
			        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
			        ft.addToBackStack(null);
			        ft.commit();
					break;

				case ConstantCommon.ALBUMS_SCREEN_ID:

					break;
				case ConstantCommon.ARTISTS_SCREEN_ID:
					 ft = getSupportFragmentManager().beginTransaction();
					 
			        ft.replace(R.id.fragment_item, new GPMArtistsFragment());
			        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
			        ft.addToBackStack(null);
			        ft.commit();
					break;
				case ConstantCommon.GENRES_SCREEN_ID:

					break;
				case ConstantCommon.PLAYLISTS_SCREEN_ID:

					break;
				case ConstantCommon.SONGS_SCREEN_ID:

					break;
				}
                        return false;
                    }
                });
        /** */
	}
	
	 @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	    	// TODO Auto-generated method stub
	    	
	    	/**Add SubMenu */
	    	menu.addSubMenu("Shuffle All");
	    	menu.addSubMenu("New playlist");
	    	menu.addSubMenu("Hide now playing bar");
	    	menu.addSubMenu("Settings");
	    	menu.addSubMenu("Help");
	    	/** */
	    	
	    	/**Search Champ */
	    	SearchView search = new SearchView(getSupportActionBar().getThemedContext());
	    	search.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
				
				@Override
				public void onFocusChange(View v, boolean hasFocus) {
					// TODO Auto-generated method stub
					if(hasFocus)
					{
						
					}
					else
					{
						
					}
				}
			});
	    	 menu.add("Search")
	         .setIcon(R.drawable.abs__ic_search)
	         .setActionView(search)
	         .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	    	/** */
	    	 
	    	 return super.onCreateOptionsMenu(menu);
	    }

	 @Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		finish();
	}

}
